package com.chinaums.fsp.sdk.request;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.chinaums.fsp.base.pgt.TransType;
import com.chinaums.fsp.sdk.base.RequestData;
import com.chinaums.fsp.sdk.base.ResponseDataWrapper;
import com.chinaums.fsp.sdk.pgt.params.CustomRequest;
import com.chinaums.fsp.sdk.pgt.params.CustomResponse;
import com.google.gson.Gson;

/**
 * 开户
 * @author hty
 *
 */
public class DraftCustomOpenTest extends BaseRequest{
public void testDraftCustomOpenRequest() throws Exception {
		
		PgtRequestFactory rf = FACTORY.factory();
		
		RequestData.Builder builder = this.createRequestDataBuilder();
		builder.setTransType(TransType.DRAFT_TRANS_CUSTOM_REGISTER.getTransCode());
		String certArray = this.createCert(); //证件信息
		String addArray = this.crateAddress(); //联系地址信息
		String manageArray = this.createManage(); //高管信息
		String stockHoldArray = this.createStockHold(); //股东信息
		String beneficiaryArray = this.crateBeneficiary(); //最终受益人信息
		CustomRequest data = CustomRequest.newBuilder()
					.setOperationType("1")
					.setEnterpriseName("享和宁杰金融信息服务（上海）有限公司")
					.setOrgNature("0103")
					.setFinanceType1("")
					.setOrgType("")
					.setOrgOwnerShipType("")
					.setIndustryType("")
					.setRegisterCapital("1000000")
					.setPaiclupCapital("")
					.setEmployeeNumber("15")
					.setSellSum("2000000")
					.setTotalAssets("10000000")
					.setMobile("15971509152")
					.setContactName("李正敏")
					.setContactId("320923198606106331")
					.setCertArray(certArray)  //证件信息
					.setAddrArray(addArray)   //联系地址信息
					.setManageArray(manageArray) //高管信息
					.setStockHolderArray(stockHoldArray) //股东信息
					.setBeneficiaryArray("") //最终受益人信息
					.setFileUrl1("5826ba93a840455597d7732eee3c6224.jpg")
					.setFileUrl2("f70cb2fb1e4e4ef592dda9e8f4c55e01.jpg")
					.setFileUrl3("")
					.setFileUrl4("3e5ef073c95d463a9e47af650c5e7f36.jpg")
					.setFileUrl5("")
					.setFileUrl6("")
					.build()
																	;
		rf.transType(TransType.DRAFT_TRANS_CUSTOM_REGISTER.getTransCode())
		.responseClass(CustomResponse.class)
		.data(data)
		;
		
		ResponseDataWrapper rdw = rf.post();
		this.printToDraft(rdw);
	}

	private String crateBeneficiary() {
		List<Map<String, String>> list = new ArrayList<>();
		Map<String, String> map = new TreeMap<String, String>();
		map.put("beneficiaryName", "");
		map.put("certType", "");
		map.put("certId", "");
		map.put("issDate", "");
		map.put("expiryDate", "");
		map.put("phoneNumber", "");
		map.put("postAddress", "");
		list.add(map);
		String jsonStr = new Gson().toJson(list);
		return jsonStr;
}

	private String createStockHold() {
		List<Map<String, String>> list = new ArrayList<>();
		Map<String, String> map = new TreeMap<String, String>();
		map.put("customerName", "陆中威");
		map.put("certType", "Ind01");
		map.put("certId", "33090319731113541X");
		map.put("regDate", "2006/08/15");
		map.put("idExpiry", "2026/08/15");
		map.put("cnIdRegCity", "8");
		map.put("relationShip", "5201");
		map.put("investmentProp", "80");
		list.add(map);
		String jsonStr = new Gson().toJson(list);
		return jsonStr;
	}

	private String createManage() {
		List<Map<String, String>> list = new ArrayList<>();
		Map<String, String> map = new TreeMap<String, String>();
		map.put("customerName", "李正敏");
		map.put("certType", "Ind01");
		map.put("certId", "320923198606106331");
		map.put("regDate", "2018/11/21");
		map.put("idExpiry", "2038/11/21");
		map.put("cnIdRegCity", "27");
		map.put("relationShip", "0103");
		list.add(map);
		String jsonStr = new Gson().toJson(list);
		return jsonStr;
	}

	private String crateAddress() {
		List<Map<String, String>> list = new ArrayList<>();
		Map<String, String> map = new TreeMap<String, String>();
		map.put("city", "");
		map.put("address1", "");
		map.put("zipCode", "");
		list.add(map);
		String jsonStr = new Gson().toJson(list);
		return jsonStr;
}

	private String createCert() {
		List<Map<String, String>> list = new ArrayList<>();
		Map<String, String> map = new TreeMap<String, String>();
		map.put("certId", "913101123243611365");
		map.put("regDate", "");
		map.put("idExpiry", "");
		map.put("cnIdRegCity", "");
		list.add(map);
		String jsonStr = new Gson().toJson(list);
		return jsonStr;
	}

}
